<template>
	<scroll-view @scrolltolower="scrolltolower" :scroll-y="true" :class="pageClass" :style="pageStyle" v-if="pageReady">
		<moxi-nav :set="navSet"></moxi-nav>
		<view v-for="(list,key) in modData" :class="list.mod_class" :key="key" :style="list.css">
			<moxi-index v-if="list.name=='plugin_info_project'" :list="list" >
		<view class="index">
			<view style="background-color: #fff;">
				<moxi-choose :field="choose" :top="navHeight"
				 @change="ch" v-model="info"></moxi-choose>
			</view>
<!-- 			 <image :src="ad.pl_img" v-if="ad.pl_img&&ad.pl_img.length"
			  mode="widthFix" style="width: 100%;" @click="navto(ad.pl_url)"></image> -->
			 <view class="search">
			 	<u-search placeholder="请输入内容" v-model="searchText" :showAction="false" bgColor="#fff"
			 		@search="searchBtn"></u-search>
			 </view>
			<view class="lists">
				<view class="list" v-for="(item, index) in listsData" :key="index" @click="goDetail(item)">
					<view class="top">
						<view class="left">{{item.name}}</view>
						<!-- <view class="right">{{item.province}}-{{item.city}}</view> -->
					</view>
					<view class="middle">
						<view class="top" style="font-size: 13px;">开始时间：{{$u.timeFormat(item.start_time, 'yyyy年mm月dd日')}}</view>
						<view class="bottom">
							<view class="tab">面积：{{item.mianji}}</view>
							<view class="tab">{{item.type}}</view>
						</view>
					</view>
					<view class="footer">
						<view class="left" style="color: #666;">{{item.province}}-{{item.city}}</view>
						<view class="right" style="display: flex;flex-direction: row;color: #666;">
							<u-icon name="eye-fill" color="#666666"></u-icon>
							<view style="margin-left: 3px;"><text>{{item.view}}</text></view>
						</view>
					</view>
				</view>
						<view style="display: flex;flex-direction: row;justify-content: center;">
				<u-divider style="padding-bottom: 10px;" text="没有更多内容了" v-if="hasMore == false"></u-divider>
				</view>
				<view v-if="hasMore == false&&!listsData.length" style="display: flex;flex-direction: row;justify-content: center;margin-bottom: 10px;">
					<view style="width: 100px;" @click="gengduo()">
						<u-button text="查看更多" icon="more-dot-fill" iconColor="#fff" :color="app_color" size="small"></u-button>
					</view>
				</view>
			</view>
		</view>
	</moxi-index>
	<moxi-index v-else :list="list"></moxi-index>
	</view>
			<moxi-tabbar :set="tabbar" v-if="tabbar.index_id"></moxi-tabbar>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				info: {
					page: 1,
					page_num: 5,
					province:"",
					city:"",
					distance:"city",
					c_time:"",
					la:"",
					ln:"",
					start_time:"",
					search:"",
					type_name:"",
					check_tag:[],
					start_daterange:[]
				},
				isGet:false,
				searchText: '',
				listsData: [],
				hasMore: true,
				choose: [ {
							name: '地区',
							type: 'city',
						}, {
							name: '距离',
							type: 'distance',
							distance: '',
							start_time:""
						}, {
							name: '筛选',
							type: 'choose',
							list: [
							{
								name: "时间排序方式",
								key: 'start_time',
								list: [{
										name: "不限",
										value: ""
									},
									{
										name: "正序",
										value: "asc"
									},
									{
										name: "倒序",
										value: "desc"
									}
								]
							},
							{
								name: "开始时间范围",
								key: 'start_daterange',
								list: []
							}
							]
						}],
						typeData:[],
						tagData:[],
						ad:{}
			}
		},
		onLoad() {
			this.locationInit()
			setTimeout(()=>{
				if(!this.isGet){
					this.get()
				}
			},1000)
			
		},
		methods: {
			gengduo(){
				this.info.distance = 'asc';
				this.info.province = 'all';
				this.clear()
				this.get()
			},
			locationInit(call){
				let self = this;
				this.moxiGetLocation((res)=>{
					if(res.latitude){
						self.info.la = res.latitude;
						self.info.ln = res.longitude;
						if(this.isGet){
							self.clear();
							self.get()
						}else{
							self.get()
						}
						
					}else{
						// self.get()
						// self.getLocationShowBox()
					}
				})
			},
			getLocationShowBox(){
				let self = this;
				uni.showModal({
					title: '当前服务需要获取您的位置',
					content: '请将位置信息设置成“使用小程序时允许”',
					success: function (res) {
						if (res.confirm) {
							 self.openSet()
						} else if (res.cancel) {
							let page = getCurrentPages();
							if(page.length>1){
								uni.navigateBack();
							}else{
								uni.redirectTo({
									url: '/pages/index/index'
								});
							}
						}
					}
				});
			},
			openSet(){
				let self = this;
				uni.openSetting({
				  success(res) {
				   if(res.authSetting['scope.userLocation']){
					   self.locationInit()
				   }else{
					   self.getLocationShowBox()
				   }
				  }
				});
			},
			ch(v) {
				
				this.info = Object.assign(this.info, v);
				this.clear()
				this.get()
			},
			searchBtn() {
				this.clear()
				this.searchText = this.searchText.trim()
				this.info.search = this.searchText
				this.get()
			},
			clear(){
				this.hasMore = true
				this.info.page = 1
				this.listsData = []
			},
			scrolltolower(){
				if(this.hasMore){
					this.info.page++;
					this.get()
				}
			},
			zh(num) {
				if (num >= 1000) {
					return (num / 1000).toFixed(1) + 'K'
				} else {
					return num.toString()
				}
			},
			goDetail(list) {
				if(list.hasPower){
					this.navto('plugin_info/projectListDetail?id=' + list.id)
				}else{
					this.msg("您无权限查看！")
				}
				
			},
			get() {
				let self = this
				this.moxiPost('/plugin/info/index/project/get',this.info,
				 function(data) {
					 console.log(data);
					 if(data.ad){
					 	self.ad = data.ad;
					 	self.$forceUpdate()
					 }
					 if(!self.typeData.length){
						 self.typeData = data.type.map(item => ({
						  	name: item,
						  	value: item
						  }))
						  self.typeData.unshift({
						  	name: '默认',
						  	value: ''
						  })
						  self.choose.unshift(
						 	 {
						 	 	name: '分类',
						 	 	type: "list",
						 	 	key: "type_name",
						 	 	list: self.typeData
						 	 }
						 )
						 self.tagData = data.tag.map(item => ({
						  	name: item,
						  	value: item
						  }))
						 self.choose[3].list.unshift({
							 name: "分类标签",
							 key: 'check_tag',
							 list: self.tagData
						 })
					 }
					 
					
					if (data.data.allpage <= self.info.page) {
						self.hasMore = false;
					}
					for(let k in data.data.data){
						self.listsData.push(data.data.data[k])
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search {
		// width: 94%;
		// margin: 10px auto;
		padding: 12px;
		background-color: #f5f5f5;
	}
	.lists {
		width: 94%;
		margin: 0 auto;

		.list {
			margin-bottom: 10px;
			padding: 10px;
			background-color: #fff;

			&:nth-last-of-type(1) {
				margin-bottom: 0;
			}

			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					font-size: 16px;
					font-weight: bold;
				}

				.right {
					font-size: 12px;color: #666;
				}
			}

			.middle {
				margin: 10px 0;
				font-size: 14px;
				color: #8f8f8f;

				.bottom {
					max-width: 70%;
					height: 24px;
					margin-top: 10px;
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					overflow: hidden;

					.tab {
						margin-right: 6px;
						padding: 4px;
						border-radius: 4px;
						background-color: #f2f2f2;
						font-size: 12px;

						&:nth-last-of-type(1) {
							margin-right: 0;
						}
					}
				}
			}

			.footer {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 12px;

				.right {
					color: #8f8f8f;
				}
			}
		}
	}

	.index {
	
		background-color: #f2f2f2;
		overflow: auto;
	}
</style>